package com.ysd.gulimall.order.interceptor;

import com.ysd.common.vo.MemberRespVo;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Component
public class LoginUserInterceptor implements HandlerInterceptor {

public  static ThreadLocal<MemberRespVo> loginUser=new ThreadLocal<>();
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //session中获取登录信息
        MemberRespVo obj=(MemberRespVo)request.getSession().getAttribute("loginUser");
        System.out.println("路径=============================："+request.getRequestURI());
        System.out.println("----------------------"+obj);
        if(obj!=null){
            loginUser.set(obj);
            return true;
        }else{
            //去登页面
            request.getSession().setAttribute("msg","请先登录");
            //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            response.sendRedirect("http://localhost:12000/login.html");
            return false;
        }

    }
}
